const mongoose = require('./db')

// 袁晨峰
let citySchema = new mongoose.Schema({
    index: String,
    children: Array
})
const orderCateSchema = new mongoose.Schema({
    name: String,
    user_id: {
        type: mongoose.ObjectId,
        ref: 'users'
    }
})

const orderSchema = new mongoose.Schema({
    name: String,
    orderId:String,
    quantity: Number,
    orderPrice:Number,
    imgUrl:String,
    type:Object,
    c_id: {
        type: mongoose.ObjectId,
        ref: 'orderCate',
        default: new mongoose.Types.ObjectId('676cb0c0aa1927093f1d9580')
    }
})

const shopSchema = new mongoose.Schema({
    name: String,
    head_img: String,
    shop_img: Array,
    user_id: {
        type: mongoose.ObjectId,
        ref: "users"
    }
})

const storeProductSchema = new mongoose.Schema({
    name: String,
    price: Number,
    salesVolume: Number,
    shop_id: {
        type: mongoose.ObjectId,
        ref: "shop"
    }
})

const activitySchema = new mongoose.Schema({
    title: String,
    reward: String,
    rule: String,
    status: Boolean,
    activity_img: Array,
    description: String
})

let cityModel = mongoose.model('city', citySchema, 'city')
let orderCateModel = mongoose.model('orderCate', orderCateSchema, 'orderCate')
let orderModel = mongoose.model('order', orderSchema, 'order')
let shopModel = mongoose.model('shop', shopSchema, 'shop')
let storeProductModel = mongoose.model('storeProduct', storeProductSchema, 'storeProduct')
let activityModel = mongoose.model('activity', activitySchema, 'activity')

// 杨志豪

// 用户表
const usersSchema = mongoose.Schema({
    username: String,
    rel: String,
    password: String,
    imgUrl: String, // 头像
    concern: Array, // 关注
    historicalSearch: Array // 历史记录
})

// 人脸表
let faseSchema = new mongoose.Schema({
    uid: String,
})
let face = mongoose.model('face', faseSchema)

// 视频表
const videoSchema = mongoose.Schema({
    videoUrl: Array, // 视频链接
    userId: {
        type: mongoose.Types.ObjectId,
        ref: "users"
    }, // 用户id
    thumbsUp: {
        type: Number,
        default: 0
    }, // 点赞
    describe: String, // 描述
    forward: {
        type: Number,
        default: 0
    }, // 转发
    collect: {
        type: Number,
        default: 0
    }, // 收藏
})
// 父级评论表
const commentSchema = mongoose.Schema({
    userId: {
        type: mongoose.Types.ObjectId,
        ref: "users"
    }, // 用户id
    videoId: {
        type: mongoose.Types.ObjectId,
        ref: "video"
    }, // 视频id
    content: String, // 内容
    created_at: String, // 评论时间
    updated_at: String, // 评论更新时间
    like_count: Number, // 点赞量（可扩展）
    is_deleted: Boolean // 是否删除
})
// 子级评论表
const childCommentSchema = mongoose.Schema({
    userId: {
        type: mongoose.Types.ObjectId,
        ref: "users"
    }, // 用户id
    videoId: {
        type: mongoose.Types.ObjectId,
        ref: "video"
    }, // 视频id
    parent_comment_id: {
        type: mongoose.Types.ObjectId,
        ref: "comment"
    }, // 父级评论ID
    content: String, // 内容
    created_at: String, // 评论时间
    updated_at: String, // 评论更新时间
    like_count: Number, // 点赞量（可扩展）
    is_deleted: Boolean, // 是否删除
    parent_id: mongoose.Types.ObjectId // 是否给子级评论
})

const usersModel = mongoose.model("users", usersSchema, "users")
const videoModel = mongoose.model("video", videoSchema, "video")
const commentModel = mongoose.model("comment", commentSchema, "comment")
const childCommentModel = mongoose.model("commentChild", childCommentSchema, "commentChild")

// 闫静瑞
const merchantTypeSchema = new mongoose.Schema({
    title: String,
    img:String
})

const merchantSchema = new mongoose.Schema({
    store: String, //店铺的名字
    contactPerson: String, //联系人
    phone: Number, // 联系人电话
    service: String, // 服务分类
    address: String, // 地区
    businessDistrict: String, // 所在商圈
    detailAddr: String, // 详细地址
    houseNumber: String, // 门牌号
    businessTime: String, // 营业时间
    IDCard: Number, // 身份证号
    IDImgUrlFront: String, //身份证正面
    IDImgUrlVerso: String, //身份证反面
    businessImgUrl: String, // 营业执照
    doorPhotoImgUrl: String, // 门头照
    otherImgUrl: String, // 其他照片
    type: {
        type: mongoose.Types.ObjectId,
        ref: 'merchantType'
    }
})

const merchantModel = mongoose.model('merchant', merchantSchema)
const merchantTypeModel = mongoose.model('merchantType', merchantTypeSchema)


const couponSchema = new mongoose.Schema({
    title: String, //套餐券的名
    num: Number, // 数量
    endPrice: Number, // 结算价
    validity: String, //有效期
    imgUrl: String, // 图片
    flag: Number, //(1是草稿， 2是审核失败，3是待审核，4已审核)
    type: {
        type: mongoose.Types.ObjectId,
        ref: 'merchant'
    }
})

const couponModel = mongoose.model('coupon', couponSchema)

// 杨博凯

// 王明辉

// 张益豪

module.exports = {
    // 杨志豪

    usersModel,
    videoModel,
    commentModel,
    childCommentModel,

    // 闫静瑞
    merchantModel,
    merchantTypeModel,
    couponModel,
    // 杨博凯
    face,
    // 王明辉

    // 张益豪

    // 袁晨峰
    cityModel,
    orderCateModel,
    orderModel,
    shopModel,
    storeProductModel,
    activityModel
}